package com.aaa.controller.api;

import com.aaa.entity.Menu;
import com.aaa.service.MenuService;
import com.aaa.vo.AddOrUpdMenu;
import com.aaa.vo.MenuVo;
import com.aaa.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @BelongsPackage: com.aaa.controller.api
 * @Description:
 * @CreateTime: 2023-03-21  19:16
 * @Author: ql
 */
@RestController
@RequestMapping("system/api/menu")
public class ApiMenuController {
    @Autowired
    private MenuService menuService;
    //index左侧菜单
    @GetMapping("/leftMenu")
    public Result<List<Menu>> getLeftMenu(){
        return menuService.getLeftMenu();
    }

    @PostMapping("/list")
    public Result<List<Menu>> list(@RequestBody MenuVo menuVo){
        System.out.println(menuVo+"==============" );
        return menuService.getAll(menuVo);
    }
    // // 查询菜单下拉树的数据
    @GetMapping("/listNoParams")
    public Result<List<Menu>> list(){
        return menuService.getAll();
    }

    @GetMapping("findByRoleId/{roleId}")
    public Result<List<Integer>> findByRoleId(@PathVariable Long roleId){
        return menuService.findByRoleId(roleId);
    }

    @PostMapping("confirmMenu")
    public Result<String> confirmMenu(Long roleId,Long[] menuIds){
        return menuService.confirmMenu(roleId,menuIds);
    }

    //查询主类目
    @GetMapping("getMenuType")
    public Result<List<Menu>> getMenuType(){
        return menuService.getMenuType();
    }

    @PostMapping("/addOrUpdMenu")
    public Result<String> AddOrUpdMenu(AddOrUpdMenu addOrUpdMenu){

        return menuService.addOrUpdMenu(addOrUpdMenu);
    }
    @GetMapping("/getMenuById/{id}")
    public Result<Menu> getMenuById(@PathVariable Long id){
        System.out.println("id = " + id);
        return menuService.getMenuById(id);
    }

    @DeleteMapping("/del/{menuId}")
    public Result<String> delByMenuId(@PathVariable Long menuId){

        return menuService.delByMenuId(menuId);
    }




}
